package com.jzo2o.customer.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jzo2o.common.utils.UserContext;
import com.jzo2o.customer.mapper.BankAccountMapper;
import com.jzo2o.customer.model.domain.BankAccount;
import com.jzo2o.customer.model.dto.request.BankAccountUpsertReqDTO;
import com.jzo2o.customer.model.dto.response.BankAccountResDTO;
import com.jzo2o.customer.service.IBankAccountService;
import org.springframework.stereotype.Service;

@Service
public class BankAccountServiceImpl extends ServiceImpl<BankAccountMapper, BankAccount> implements IBankAccountService {
//    @Override
//    public void registerBankAccount(BankAccountUpsertReqDTO reqDTO) {
//        BankAccount bankAccount = BeanUtil.toBean(reqDTO, BankAccount.class);
//        bankAccount.setId(UserContext.currentUserId());
//        bankAccount.setType(3);
//        save(bankAccount);
//    }

    @Override
    public void saveOrUpdateBankAccount(BankAccountUpsertReqDTO reqDTO) {
        BankAccount bankAccount = BeanUtil.toBean(reqDTO, BankAccount.class);
        bankAccount.setId(UserContext.currentUserId());
        bankAccount.setType(3);
        saveOrUpdate(bankAccount);
    }

    /**
     * 查询当前用户银行账户
     * @return
     */
    @Override
    public BankAccountResDTO queryCurrentUserBankAccount() {
        Long userId = UserContext.currentUserId();
        BankAccount bankAccount = getById(userId);
        return BeanUtil.toBean(bankAccount, BankAccountResDTO.class);

    }
}
